﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yaxunsoft.CasesManagement;
using FantastPlatform.Framework.Core;
using FantastPlatform.Framework.IModel;

namespace FantastPlatform.Decision.UI
{
    public partial class Default : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //清除页面缓存
            Page.Response.Buffer = false;
            Page.Response.Cache.SetNoStore();
            try
            {
                if (Session["PolicemanName"] != null)
                {
                    if (LoginEmployee != null)
                    {
                        IList<IRole> roleList = LoginEmployee.User.Roles;
                        DateTime? startTime = getWeekStartTime();
                        this.loguser.Text = LoginEmployee.Name;
                        IOrganization org = (from o in LoginEmployee.EmployeePosts
                                             where o.Enable = true
                                             select o.Post.Organization).FirstOrDefault();


                        List<string> roles = new List<string>();
                        foreach (IRole role in roleList)
                        {
                            roles.Add(role.Name);
                        }
                    }
                }
                else
                {
                    Response.Redirect(AppUrl + "/SSLLogin.aspx", true);
                }
            }
            catch (Exception ex)
            {
                //Response.Redirect(AppUrl + "/Error.aspx", true);
            }
        }


        private DateTime? getWeekStartTime()
        {
            DateTime now = DateTime.Now;
            DayOfWeek weekDay = now.DayOfWeek;
            DateTime startTime = now.AddDays(-Convert.ToInt32(weekDay) + 1).Date;
            if (weekDay == 0)
                startTime = now.AddDays(-7 + 1).Date;

            return startTime;
        }
        public  bool GetAdminIII()
        {
            return true;
        }
        public  bool GetAdminII()
        {
            if (LoginEmployee != null)
            {
                if (LoginEmployee.User != null)
                {
                    IList<IRole> roleList = LoginEmployee.User.Roles;
                    List<string> roles = new List<string>();
                    foreach (IRole role in roleList)
                    {
                        roles.Add(role.Name);
                    }
                    if (roles.Contains("社区二级管理员"))
                    {
                        return true;
                    }
                }
            }
            return false;
        }
        public  bool GetAdminI()
        {

            if (LoginEmployee != null)
            {
                if (LoginEmployee.User != null)
                {
                    IList<IRole> roleList = LoginEmployee.User.Roles;
                    List<string> roles = new List<string>();
                    foreach (IRole role in roleList)
                    {
                        roles.Add(role.Name);
                    }
                    if (roles.Contains("社区一级管理员") || roles.Contains("管理员"))
                    {
                        return true;
                    }
                }
            }
            return false;
        }
    }
}
